package cn.ncupyh.comptest;
//河内塔
public class TowerOfHanoi {
    public static void main(String[] args) {
        //将pos1位置的盘子全都移到pos3上面
        hanoi(1,'A','B','C');
        System.out.println();
        hanoi(2,'A','B','C');
        System.out.println();
        hanoi(3,'A','B','C');
        System.out.println();

    }

    private static void hanoi(int n, char pos1, char pos2, char pos3) {
        if(n==1){
            move(pos1,pos3);
            return;
        }
        hanoi(n-1,pos1,pos3,pos2);
        move(pos1,pos3);
        hanoi(n-1,pos2,pos1,pos3);
    }

    private static void move(char pos1, char pos3) {
        System.out.print(pos1+"->"+pos3+" ");
    }
}
